package com.ns.sbs.oauth.acc4log.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ns.core.annotations.ReqLog;
import com.ns.core.bo.IdsBO;
import com.ns.core.utils.sg.ResultOk;
import com.ns.sbs.oauth.acc4log.bo.AccLogPageBO;
import com.ns.sbs.oauth.acc4log.dto.Acc4LogPageDto;
import com.ns.sbs.oauth.acc4log.service.IAcc4LogService;
import com.ns.sbs.oauth.acc4log.vo.AccLoginVO;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;


/**
 * 日志相关操作
 *
 * @author lw
 */
@RestController
@RequestMapping("/sso/log/")
@RequiredArgsConstructor
@CrossOrigin
public class SsoLogController {

    /**
     * 底层 Mapper 对象
     */
    private final IAcc4LogService service;

    /**
     * 删
     *
     * @param id 参数
     */
    @GetMapping("delete")
    @ReqLog(module = "登录日志模块", name = "删")
    public ResultOk delete(Long id) {
        return ResultOk.getByBoolean(service.removeById(id));
    }

    /**
     * 删 - 根据id列表
     */
    @PostMapping("deleteByIds")
    @ReqLog(module = "登录日志模块", name = "批量删")
    public ResultOk deleteByIds(@RequestBody IdsBO bo) {
        return ResultOk.getByBoolean(service.removeBatchByIds(bo.getIds()));
    }

    /**
     * 查 - 根据id
     *
     * @param id 参数
     */
    @GetMapping("getById")
    @ReqLog(module = "登录日志模块", name = "查")
    public ResultOk getById(Long id) {
        AccLoginVO s = service.getById(id);
        return ResultOk.getSuccessData(s);
    }

    /**
     * 查集合 - 根据条件（参数为空时代表忽略指定条件）
     */
    @PostMapping("getList")
    @ReqLog(module = "登录日志模块", name = "集合")
    public ResultOk getList(@RequestBody AccLogPageBO bo) {
        Acc4LogPageDto dto = new Acc4LogPageDto();
        BeanUtils.copyProperties(bo, dto);
        Page<AccLoginVO> list = service.getList(dto);
        return ResultOk.getPageData(list.getTotal(), list.getRecords());
    }

}
